﻿
using CPPEI.Coolzon.Core;
using CPPEI.Coolzon.Core.Repositories.SQL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CPPEI.Coolzon.BrowserAppHost
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            using (DbContext context = new DbContext())
            {
                SqlUserRepository userrepository = new SqlUserRepository();
               Core.Data.User user = userrepository.GetUser(context, this.txtUserName.Text.Trim());
               if (user!= null && user.Password == txtPassword.Text.Trim())
                {
                    System.Web.Security.FormsAuthentication.SetAuthCookie(user.Account,true);
                    Response.Redirect("LoadUserSolution.aspx");
                }
                else
                {
                    lblErrorMsg.Text = "用户名或密码错误！";
                    lblErrorMsg.Visible = true;
                }
            }
        }
    }
}